import requests


def get_shortest_route_info(origin, destinations, api_key):
    # 存储每个目的地的最短路程和路径数量
    shortest_route_info = {}

    for destination in destinations:
        # 高德地图路径规划 API 的 URL
        url = "https://restapi.amap.com/v3/direction/driving"

        # 请求参数
        params = {
            'key': api_key,
            'origin': origin,
            'destination': destination
        }

        # 发送请求并获取响应
        response = requests.get(url, params=params)
        if response.status_code == 200:
            # 解析响应内容
            result = response.json()
            if result['status'] == '1':
                # 获取所有路径的距离
                distances = [int(path['distance']) for path in result['route']['paths']]
                # 找到最短的距离
                shortest_distance = min(distances)
                # 获取路径数量
                route_count = len(result['route']['paths'])
                # 存储到字典
                shortest_route_info[destination] = {'shortest_distance': shortest_distance, 'route_count': route_count}
            else:
                print(f"API 请求失败，目的地 {destination}：", result['info'])
        else:
            print(f"请求失败，HTTP 状态码：{response.status_code}, 目的地 {destination}")

    return shortest_route_info


# 使用示例
api_key = '39fd6404c3cd21e25ca929002bc40768'  # 替换为您的 API Key
origin = '114.328656,30.622718'  # 中心点经纬度
destinations = ['114.316545,30.622919',
 '114.318925,30.616371',
 '114.316236,30.623166',
 '114.318720,30.616108',
 '114.315864,30.622245',
 '114.315937,30.625836',
 '114.317843,30.630140',
 '114.320427,30.632740',
 '114.313005,30.620775',
 '114.312770,30.623004',
 '114.312886,30.624770',
 '114.312626,30.622755',
 '114.312589,30.623437',
 '114.312230,30.619362',
 '114.314630,30.630850',
 '114.311291,30.623335',
 '114.310742,30.625073',
 '114.310739,30.625344',
 '114.313406,30.631255',
 '114.315389,30.633498',
 '114.310793,30.618928',
 '114.311938,30.614776',
 '114.309533,30.622171',
 '114.309929,30.626417',
 '114.309460,30.628134',
 '114.318373,30.637783',
 '114.311108,30.613859',
 '114.306545,30.620879',
 '114.307115,30.617845',
 '114.344655,30.608793',
 '114.312874,30.608427',
 '114.350328,30.616318',
 '114.310761,30.635487',
 '114.309687,30.634736',
 '114.306815,30.614881',
 '114.306485,30.630356',
 '114.320202,30.641978',
 '114.305219,30.618500',
 '114.351413,30.615973',
 '114.338119,30.603451',
 '114.311474,30.637646',
 '114.305922,30.630579',
 '114.352319,30.616669',
 '114.350402,30.612478',
 '114.310581,30.637527',
 '114.352406,30.616010',
 '114.347110,30.607598',
 '114.303870,30.617114',
 '114.334311,30.644240',
 '114.341121,30.603111',
 '114.302687,30.621611',
 '114.302362,30.621982',
 '114.302291,30.621181',
 '114.307257,30.609083',
 '114.301761,30.621292',
 '114.335636,30.645154',
 '114.342936,30.602735',
 '114.353115,30.611861',
 '114.353565,30.612374',
 '114.355447,30.616652',
 '114.309851,30.605176',
 '114.317160,30.644645',
 '114.306500,30.607050',
 '114.299950,30.622604',
 '114.299909,30.623085',
 '114.339483,30.599682',
 '114.338957,30.599468',
 '114.300862,30.615815',
 '114.338910,30.599439',
 '114.326914,30.647917',
 '114.308033,30.640765',
 '114.299115,30.623036',
 '114.303078,30.609968',
 '114.300526,30.614435',
 '114.305652,30.606299',
 '114.320229,30.647403',
 '114.326278,30.648445',
 '114.305482,30.606289',
 '114.340973,30.599015',
 '114.355167,30.609902',
 '114.299993,30.613664',
 '114.303534,30.637954',
 '114.310441,30.601236',
 '114.302097,30.636453',
 '114.303285,30.638032',
 '114.303265,30.638037',
 '114.300084,30.633163',
 '114.309143,30.643574',
 '114.304566,30.605669',
 '114.304412,30.605751',
 '114.331551,30.649507',
 '114.359957,30.622086',
 '114.304146,30.639769',
 '114.315399,30.647781',
 '114.296846,30.626631',
 '114.326583,30.650394',
 '114.360697,30.619715',
 '114.344729,30.598551',
 '114.360222,30.616552',
 '114.307671,30.601484',
 '114.303278,30.605165',
 '114.306322,30.643269',
 '114.333574,30.650625',
 '114.339851,30.596034',
 '114.316851,30.649230',
 '114.308988,30.645589',
 '114.303039,30.640943',
 '114.319076,30.650316',
 '114.352176,30.602197',
 '114.343603,30.596903',
 '114.361420,30.616429',
 '114.306649,30.600828',
 '114.306165,30.644422',
 '114.362664,30.624171',
 '114.300738,30.605942',
 '114.355853,30.605067',
 '114.350456,30.600058',
 '114.296479,30.633178',
 '114.306118,30.600337',
 '114.356112,30.604693',
 '114.294947,30.615798',
 '114.298723,30.637937',
 '114.294112,30.619314',
 '114.327420,30.652634',
 '114.312356,30.649584',
]  # 周边点经纬度列表

shortest_route_info = get_shortest_route_info(origin, destinations, api_key)
for dest, info in shortest_route_info.items():
    print(f"目的地: {dest}, 最短路程: {info['shortest_distance']}米, 路径数量: {info['route_count']}")